/*
 * ModoForm.java
 *
 * Created on 1 de julio de 2008, 20:46
 */

package View;

import Model.Congreso;
import Model.Usuario;
import Servicio.Proxy;
import com.birosoft.liquid.LiquidLookAndFeel;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author  Gigin
 */
public class Contrasena extends javax.swing.JFrame {
    private ArrayList<Congreso> mCongresos;
    private Controller.SegPedidoController ppalSeg;
    private SegPedidoForm SPF;

  
    
    
    public Contrasena() {
       
    }

    /** Creates new form ModoForm */
    public Contrasena(Controller.SegPedidoController frame, SegPedidoForm spf){
        this.ppalSeg = frame;
        this.SPF=spf;
        this.setAlwaysOnTop(true);
        iniciarPantalla();
        
    }
    
    private void iniciarPantalla(){
    // Se carga el Look and Feel
        try {
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");   
        } catch (Exception e) { }
        LiquidLookAndFeel.setStipples(false);
        
        
        initComponents();
       
        
        
        
    
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButtonAceptar = new javax.swing.JButton();
        jLabelUsuario = new javax.swing.JLabel();
        jLabelPass = new javax.swing.JLabel();
        jTextUsuario = new javax.swing.JTextField();
        jTextPass = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 1, 24));
        jLabel1.setForeground(new java.awt.Color(94, 148, 189));
        jLabel1.setText("Por favor identifíquese");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 20, -1, -1));

        jButtonAceptar.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jButtonAceptar.setForeground(new java.awt.Color(94, 148, 189));
        jButtonAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_normal.gif"))); // NOI18N
        jButtonAceptar.setToolTipText("Ingresar con el modo seleccionado");
        jButtonAceptar.setBorderPainted(false);
        jButtonAceptar.setContentAreaFilled(false);
        jButtonAceptar.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_deshabilitado.gif"))); // NOI18N
        jButtonAceptar.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_presionado.gif"))); // NOI18N
        jButtonAceptar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Aceptar_mouse.gif"))); // NOI18N
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });
        jPanel1.add(jButtonAceptar, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 180, 125, 22));

        jLabelUsuario.setText("Usuario:");
        jPanel1.add(jLabelUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 90, -1, -1));

        jLabelPass.setText("Contraseña:");
        jPanel1.add(jLabelPass, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 120, -1, -1));
        jPanel1.add(jTextUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 90, 130, -1));

        jTextPass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextPassActionPerformed(evt);
            }
        });
        jPanel1.add(jTextPass, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 120, 130, -1));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_normal.gif"))); // NOI18N
        jButton1.setToolTipText("Cancelar");
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_deshabilitado.gif"))); // NOI18N
        jButton1.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_presionado.gif"))); // NOI18N
        jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Botones/Cancelar_mouse.gif"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 180, 125, 22));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed


    Usuario usr;

        try{
            usr = Proxy.validarUsuario(jTextUsuario.getText(), String.valueOf(jTextPass.getPassword()));
            if (usr == null){
                this.setAlwaysOnTop(false);
                JOptionPane.showMessageDialog(new JFrame(), "El usuario no existe o su contraseña es incorrecta", "Atención", JOptionPane.WARNING_MESSAGE);
                jTextPass.setText("");
                jTextUsuario.setText("");
                jTextUsuario.grabFocus();
                jTextUsuario.setCaretPosition(0);
            }else{
                    
                    ppalSeg.eliminarPedidoSeleccionado();
                    ppalSeg.setPedidoElim(null);
                    SPF.actualizar();
                    this.dispose();
            }
            }catch (Exception e){
                    usr = null;
                    JOptionPane.showMessageDialog(new JFrame(), "El usuario no existe o su contraseña esincorrecta", "Atención", JOptionPane.WARNING_MESSAGE);
        }
        
        
    
    
    
}//GEN-LAST:event_jButtonAceptarActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    
    this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

private void jTextPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextPassActionPerformed
this.jButtonAceptarActionPerformed(evt);
}//GEN-LAST:event_jTextPassActionPerformed

   /** Carga el combo de Congresos */
    

    
 
    
    
   
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelPass;
    private javax.swing.JLabel jLabelUsuario;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jTextPass;
    private javax.swing.JTextField jTextUsuario;
    // End of variables declaration//GEN-END:variables

}
